using System;
using Deepcode.Flux.Core.Codons;
using Deepcode.Flux.Core.Extensions;
using Deepcode.Flux.Core.Extensions.Codons;
using Deepcode.Flux.Core.Systems.UI.Menus;

namespace Deepcode.Flux.Core.Codons.Menus
{
	/// <summary>
	/// <MenuItemTool
	///		id="qmtaskpad" 
	///		href="~/admin/Menu/taskpad.aspx" 
	///		caption="My Taskpad" 
	///		settitle="Flux.NET Taskpad"
	///		permission="" />
	/// 
	/// Codon representing a menu entry that will navigate the content pane.
	/// 
	/// </summary>
	[XmlCodonName("MenuItemTool")]
	public class MenuItemToolCodon : AbstractPermissionCodon
	{
		[XmlCodonAttribute("href")]
		private string href = "";
		[XmlCodonAttribute("caption")]
		private string caption = "";
		[XmlCodonAttribute("settitle")]
		private string settitle = "";

		public override object BuildItem(object owner, System.Collections.ArrayList subItems)
		{
			if( !CheckUser() ) return null;

			if( owner == null ) 
				throw new Exception("BuildItem failed on MenuItemTool codon due to owner not being a System.Web.UI.Page");

			System.Web.UI.Page ownerpage = (System.Web.UI.Page) owner;
			MenuToolLink link = new MenuToolLink(ownerpage, href, caption, settitle );
			return link;
		}
	}
}
